const app = getApp();
const request = require('../../utils/request.js');

Page({


  /**
   * 页面的初始数据
   */
  data: {
    pageNo: 1,
    pageSize: 10,
    articleList: [{
        "content": "伤口护理伤口护理伤口护理伤口护理",
        "coverPicture": "",
        "createTime": "",
        "id": 1,
        "linkUrl": 'https://images.unsplash.com/photo-1551334787-21e6bd3ab135?w=640',
        "readCnt": 1,
        "status": "",
        "tagId": 1,
        "tagName": "月子护理",
        "title": "我是知识的标题",
        "type": "",
        "updateTime": ""
      },
      {
        "content": "伤口护理伤口护理伤口护理伤口护理",
        "coverPicture": "",
        "createTime": "",
        "id": 1,
        "linkUrl": 'https://images.unsplash.com/photo-1551334787-21e6bd3ab135?w=640',
        "readCnt": 1,
        "status": "",
        "tagId": 1,
        "tagName": "月子护理",
        "title": "我是知识的标题",
        "type": "",
        "updateTime": ""
      },
      {
        "content": "伤口护理伤口护理伤口护理伤口护理",
        "coverPicture": "",
        "createTime": "",
        "id": 1,
        "linkUrl": 'https://images.unsplash.com/photo-1551334787-21e6bd3ab135?w=640',
        "readCnt": 1,
        "status": "",
        "tagId": 1,
        "tagName": "月子护理",
        "title": "我是知识的标题",
        "type": "",
        "updateTime": ""
      },
      {
        "content": "伤口护理伤口护理伤口护理伤口护理",
        "coverPicture": "",
        "createTime": "",
        "id": 1,
        "linkUrl": 'https://images.unsplash.com/photo-1551334787-21e6bd3ab135?w=640',
        "readCnt": 1,
        "status": "",
        "tagId": 1,
        "tagName": "月子护理",
        "title": "我是知识的标题",
        "type": "",
        "updateTime": ""
      },
      {
        "content": "伤口护理伤口护理伤口护理伤口护理",
        "coverPicture": "",
        "createTime": "",
        "id": 1,
        "linkUrl": 'https://images.unsplash.com/photo-1551334787-21e6bd3ab135?w=640',
        "readCnt": 1,
        "status": "",
        "tagId": 1,
        "tagName": "月子护理",
        "title": "我是知识的标题",
        "type": "",
        "updateTime": ""
      },
    ],
    id: ""
  },
  
  getArticleList () {
    const params = {
      pageNo: this.data.pageNo,
      pageSize: this.data.pageSize,
      param: {
        operation: this.data.id
      }
    }
    request._post("/woman/api/article/list", params).then(res => {
      if(res.code === "0") {
        const data = res.data;
        if(this.data.pageNo === 1) {
          this.setData({
            articleList: data
          })
        } else {
          const oldData = this.data.articleList
          this.setData({
            articleList: oldData.concat(data)
          })
        }
      }
    })
  },
  setBarTitle () {
    if(this.data.id === "1") {
      app.setBarTitle("今日知识")
    } else {
      app.setBarTitle("热门话题")
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log(options, 'options===')
    const { id } = options;
    this.setData({ id });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    this.getArticleList();
    this.setBarTitle();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    // 标题栏显示刷新图标，转圈圈
    wx.showNavigationBarLoading();
    this.setData({
      pageNo: 1
    })
    setTimeout(() => {
      this.getArticleList();
      wx.hideNavigationBarLoading();
      wx.stopPullDownRefresh();
    }, 300)
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    console.log('onReachBottom===')
    const pageNo = this.data.pageNo + 1;
    this.setData({
      pageNo
    })
    this.getArticleList();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})